package com.houmeiyuan.huiguniang.common;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class OrderInfoUtils {

    /**
     * 生成N位随机数字
     * @return
     */
    private static String getSixNumber(int n) {
        StringBuilder builder =new StringBuilder();
        for (int i = 0; i < n; i ++) {
            Random rd = new Random();
            builder.append(rd.nextInt(10));
        }
        return builder.toString();
    }

    public static String getDateNumber(){
        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyyMMddHHmmssSSS");
        return dateFormat.format(new Date());
    }

    /**
     * 获取订单号
     *  订单号格式: 时间戳（精确到毫秒）+ 6位随机数字
     * @return
     */
    public static String getOrderNumber() {

        StringBuilder builder = new StringBuilder();
        builder.append(getDateNumber()).append(getSixNumber(6));
        return builder.toString();
    }


    /**
     * 获取支付账单号
     *  订单号格式: 时间戳（精确到毫秒）+ 4位随机数字
     * @return
     */
    public static String getTradeNumber() {

        StringBuilder builder = new StringBuilder();
        builder.append(getDateNumber()).append(getSixNumber(4));
        return builder.toString();
    }


}
